package com.two.lbms.lzl.controller;

import com.two.lbms.base.BaseController;
import com.two.lbms.base.ResultInfo;
import com.two.lbms.lzl.query.DictionaryListQuery;
import com.two.lbms.lzl.service.DictionaryListService;
import com.two.lbms.utils.CookieUtil;
import com.two.lbms.vo.DictionaryList;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Controller
@RequestMapping("/dictionary")
public class DictionaryListController extends BaseController {
    @Resource
    private DictionaryListService dictionaryListService;
    @RequestMapping("/index")
    public String toDictionaryPage() {

        return "lzl/dictionary";
    }

    //多条件分页查询字典
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> querySaleChanceByParams(DictionaryListQuery dictionaryListQuery){
        return dictionaryListService.querySaleChanceByParams(dictionaryListQuery);
    }
    /*添加字典管理的数据*/
    @RequestMapping("/add")
    @ResponseBody
    public ResultInfo addDictionaryList(HttpServletRequest request, DictionaryList dictionaryList){

        //调用service层的添加方法
        System.out.println(dictionaryList);
        dictionaryListService.addDictionaryList(dictionaryList);
        return success("字典数据添加成功");
    }
    /*进入添加修改字典数据页面*/
    @RequestMapping("/toIndexPage")
    public String toIndexPage(Integer dictionaryListId,HttpServletRequest request){

        if (dictionaryListId !=null){
            //通过id查询字典数据
            DictionaryList dictionaryList = dictionaryListService.selectByPrimaryKey(dictionaryListId);
            //将数据设置到请求域中
            request.setAttribute("dictionaryList",dictionaryList);
        }
        return "lzl/add_update";
    }
  //*更新字典模块的数据*//
    @RequestMapping("/update")
    @ResponseBody
    public ResultInfo updateDictionary(DictionaryList dictionaryList){
        dictionaryListService.updateDictionary(dictionaryList);
        return success("字典数据更新成功");
    }
   //*数据添加与更新表单⻚⾯视图转发*/



    /*删除操作*/
    @RequestMapping("/delete")
    @ResponseBody
    public ResultInfo deleteDictionary(Integer [] ids){
        //调用service层的删除方法
        dictionaryListService.deleteDictionary(ids);
        return success("字典数据删除成功");
    }
}
